<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
            var Book = (function () {
                //静态私有属性
                var num = 0
                var pri = '我是静态私有属性'
                //静态私有方法
                function checkId(params) {
                    return '我是静态私有方法'
                }
                //返回构造函数
                return function (newId,newName,newPrice) {
                    //闭包中的私有变量
                    var writer
                    //闭包中的私有方法
                    function checkWriter(params) {
                        
                    }
                    //特权方法,可以访问到类到私有方法
                    this.getName = function (params) {}
                    this.getId = function name(params) {
                        return pri
                    }
                    this.getnum = function (params) {
                        return '现在的num---'+num
                    }
                    //公有属性
                    this.newId = newId
                    this.newName = newName
                    this.newPrice = newPrice
                    //公有方法
                    this.copy = function (params) {}
                    //构造器
                    function setName(newId) {
                        this.newId = newId
                    }
                    function setId(newId) {
                        this.newId = newId
                    }
                    function setName(newId) {
                        this.newId = newId
                    }
                    //访问类的私有方法
                    this.getCheckId  = function(params) {
                        let res = checkId()
                        return res
                    }
                    //访问私有变量
                    num ++
                    if (num > 3)
                        throw new Error('数量不够了')
                }
            })()
            //静态公有属性
            Book.isChinese = true
            //静态公有方法
            Book.resetTime = function (params) {
                return 'resetTime'
            }
            //通过类的prototype创建
            //两种添加方法，方法一是一一为原型对象属性赋值
            //方法二是将一个对象赋值给原型对象
            Book.prototype = {
                isEnglish :false,
                display : function (params) {
                    return 'display'
                }
            }
            //创建实例对象
            var book1 = new Book(1,'了不起的比尔盖茨',55)
            console.log(book1)
            console.log(book1.getCheckId())
            //直接访问不可以，通过闭包可以
            //console.log(book1.num)
            console.log(book1.getId())
            console.log(book1.getnum())
            var book2 = new Book(2,'老人与海',34)
            console.log(book2)
            console.log(book2.getnum())
            var book3 = new Book(3,'福尔摩斯',23)
            console.log(book3)
            console.log(book3.getnum())
            
    </script>
</body>
</html>